package com.lenovo.lcdm.dcm.common.util;

public class VersionUtil {

    public static String getNextVersion(String version) {
        char[] versionCharArray = version.toCharArray();
        int lastNum = "Z".toCharArray()[0];
        boolean needAddNewVersion = true;
        char[] resultCharArray = new char[versionCharArray.length];
        for (int i = versionCharArray.length - 1; i >= 0; i--) {
            char next;
            if (needAddNewVersion) {
                if (versionCharArray[i] == lastNum) {
                    next = "A".toCharArray()[0];
                } else {
                    int currentInt = versionCharArray[i];
                    next = (char) (currentInt + 1);
                    needAddNewVersion = false;
                }
            } else {
                next = versionCharArray[i];
            }
            resultCharArray[i] = next;
        }
        StringBuilder result = new StringBuilder();
        if (needAddNewVersion) {
            result.append("A");
            for (char c : resultCharArray) {
                result.append(c);
            }
        } else {
            for (char c : resultCharArray) {
                result.append(c);
            }
        }
        return String.valueOf(result);
    }
}
